import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

import user from './modules/user.js';
import device from './modules/device.js';

const store = new Vuex.Store({
  modules: {
    user,
    device
  },
  plugins: [
    // 为 user 模块创建持久化插件实例
    createPersistedState({
      storage: {
        getItem: (key) => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: (key) => uni.removeStorageSync(key),
      },
      key: "user", // 设置 user 模块的缓存 key
      paths: ['user'] ,// 仅持久化 user 模块
	  render(state){
		return {...state};
      }
    }),
    // 为 device 模块创建持久化插件实例
    createPersistedState({
      storage: {
        getItem: (key) => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: (key) => uni.removeStorageSync(key),
      },
      key: "device", // 设置 device 模块的缓存 key
      paths: ['device'] ,// 仅持久化 device 模块
	  render(state){
		return {...state};
	  }
    })
  ]
});

export default store;